package com.ttg.web.dao.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttg.model.mapper.CostManageAcctComprehensiveAnalysisMapper;
import com.ttg.model.po.AcctAnalysisPO;
import com.ttg.model.pojo.CostManageAcctComprehensiveAnalysis;
import com.ttg.model.pojo.CostManageAcctDepositAnalysis;
import com.ttg.web.dao.CostManageAcctComprehensiveAnalysisDao;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * (TblCostManageAcctComprehensiveAnalysis) daoImpl
 *
 * @author chenyou
 * @datetime 2025-09-23 15:40:24
 */
@Service
public class CostManageAcctComprehensiveAnalysisDaoImpl extends ServiceImpl<CostManageAcctComprehensiveAnalysisMapper, CostManageAcctComprehensiveAnalysis> implements CostManageAcctComprehensiveAnalysisDao {

    @Override
    public CostManageAcctComprehensiveAnalysis getByUnique(String intervalType, Integer dimType, Integer itemType, String year, String month) {
        LambdaQueryWrapper<CostManageAcctComprehensiveAnalysis> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CostManageAcctComprehensiveAnalysis::getCmacIntervalType,intervalType)
                .eq(CostManageAcctComprehensiveAnalysis::getCmacAcctDimType,dimType)
                .eq(CostManageAcctComprehensiveAnalysis::getCmacItemType,itemType)
                .eq(CostManageAcctComprehensiveAnalysis::getCmacYear,year)
                .eq(CostManageAcctComprehensiveAnalysis::getCmacMonth,month);
        return getOne(wrapper);
    }

    @Override
    public void saveOrUpd(CostManageAcctComprehensiveAnalysis comprehensiveAnalysis) {
        CostManageAcctComprehensiveAnalysis old = getByUnique(comprehensiveAnalysis.getCmacIntervalType(),comprehensiveAnalysis.getCmacAcctDimType(),comprehensiveAnalysis.getCmacItemType(),comprehensiveAnalysis.getCmacYear(),comprehensiveAnalysis.getCmacMonth());
        if(Objects.isNull(old)){
            save(comprehensiveAnalysis);
        }else{
            comprehensiveAnalysis.setCmacId(old.getCmacId());
            updateById(comprehensiveAnalysis);
        }
    }

    @Override
    public List<CostManageAcctComprehensiveAnalysis> getByParam(AcctAnalysisPO po) {
        return baseMapper.getByParam(po);
    }
}

